﻿using System;
using UnityEngine.UI;

public class EditInfoPanel : AppUI
{
    public Text titleText;
    public InputField inputField;
    //public Text inputText;
    public Text tipsText;
    public Text inputCountText;

    public int maxInputCount = 800;

    int m_Type;
    public void InitIntroduction(int introductionType, string title,string tips,string defaultValue)
    {
        m_Type = introductionType;

        this.titleText.text = title;
        if (!string.IsNullOrEmpty(tips))
        {
            this.tipsText.text = tips + "（请认真填写，乱填会被举报封禁的哦）";
            inputField.text = "";
        }
        else
        {
            this.tipsText.text = "";
           inputField.text = defaultValue;
        }
        //inputText.text = "";
        inputField.onValueChanged.AddListener(OnValueChanged);
        OnValueChanged("");
    }

    private void OnValueChanged(string arg0)
    {
        this.inputCountText.text = $"{arg0.Length}/{maxInputCount}";
    }

    public void OnClickSave()
    {
        string content = this.inputField.text;
        RequestServerController.instance.ReqUpdateIntroduction(m_Type, content, (ret) =>
        {
            var uh = UIController.ShowUI<UserHomePanel>();
            uh.RefreshIntroduction(m_Type, content);
        });
    }

    public void GoBack()
    {
        UIController.ShowUI<UserHomePanel>();
    }


}
